home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
FM Towns: Free Software Collection 10
/
FM Towns Free Software Collection 10.iso
/
ms_dos
/
tool
/
fapxtool
/
src
/
txm
/
txmforum.c
< prev
next >
Wrap
C/C++ Source or Header
|
1995-01-06
|
4KB
|
180 lines
/***************
*
* txm\txmforum.c
*/
#include "txm.h"
/*
┌→WRK(workfile) →rename LOG(logfile)
LOG(logfile) →┤
└→001,...(mfile)
*/
/* マージファイル更新チェック/必要ならマージファイルを新しくする/情報ファイル更新(フォーラム/HP用) */
int fchknewmerge(char *buf1, char *buf2, FILE **fp)
{
long article; /* 発言番号 */
union _LONG ltime;
int year = 0, month = 0, day = 0, hour = 0, minute = 0;
unsigned short ym = 0, dhm = 0;
int newflag = FALSE;
char ext[6];
article = atol(buf1);
sscanf(buf2, "%2d/%2d/%2d %2d:%2d",
&year, &month, &day, &hour, &minute);
ym = (year << 4) | month;
dhm = (day << 11) | (hour << 6) | minute;
ltime.s.h = ym;
ltime.s.l = dhm;
switch (nextmerge) {
case 0:
if (filelength(fileno(*fp)) >= nextvalue) {
newflag = TRUE;
}
break;
case 1:
if (nextvalue == 1) {
if (nowinfo->art > article) {
newflag = TRUE;
}
}
else if ((article % nextvalue) == 1) {
newflag = TRUE;
}
break;
case 2:
if (nowinfo->ltime.s.h != 0) {
if (nowinfo->ltime.s.h < ym) {
newflag = TRUE;
}
}
break;
}
if (nowinfo->ltime.x > ltime.x) {
newflag = FALSE;
}
else {
nowinfo->ltime.x = ltime.x;
}
if (nowinfo->art == 0) {
newflag = FALSE;
}
nowinfo->art = (unsigned short)article;
if (newflag) {
fclose(*fp);
nowinfo->ext += 1;
sprintf(ext, ".%03d", nowinfo->ext);
makenewextname(logfile, mfile, ext);
if ((*fp = fopen(mfile, "wb")) == NULL) {
return ERROR;
}
fputs(head1, *fp);
fputs(head2, *fp);
fputs(mesname, *fp);
}
else {
return FALSE;
}
return TRUE;
}
/* フォラーム/パティオマージ */
int forummerge()
{
FILE *fr, *fw, *fm;
int ret, mesnameflg = FALSE;
long nowsize, limitsize;
char *vbuf;
/* printf("forummerge()\n"); */
if ((fr = fopen(logfile, "rb")) == NULL) {
return FALSE;
}
/* setvbufのmallocは取りっ放し(終了時の自動開放??) */
setvbuf(fr, malloc(VBUFSIZE), _IOFBF, VBUFSIZE);
if ((fm = fopen(mfile, "ab")) == NULL) {
fclose(fr);
return FALSE;
}
/* setvbufのmallocは取りっ放し(終了時の自動開放??) */
setvbuf(fm, vbuf = malloc(VBUFSIZE), _IOFBF, VBUFSIZE);
fgets(head1, 80, fr); /* ヘッダ読み込み */
fgets(head2, 80, fr); /* ヘッダ読み込み */
if (filelength(fileno(fm)) == 0) {
fputs(head1, fm);
fputs(head2, fm);
mesnameflg = TRUE;
}
limitsize = (long)minrun * 1024;
nowsize = filelength(fileno(fr));
nowsize -= strlen(head1);
nowsize -= strlen(head2);
while (nowsize > limitsize) {
if (fgets(line1, 100, fr) == NULL) {
break;
}
nowsize -= strlen(line1);
if (*line1 == '-') {
strcpy(mesname, line1);
if (mesnameflg) {
fputs(mesname, fm);
mesnameflg = FALSE;
}
}
else if (matchstr(log_mes1, line1) || matchstr(log_mes2, line1)) {
if (fgets(line2, 100, fr) == NULL) {
break;
}
nowsize -= strlen(line2);
if (ret = fchknewmerge(line1, line2+7, &fm)) {
if (ret == ERROR) {
fclose(fr);
return FALSE;
}
}
fputs(line1, fm);
fputs(line2, fm);
for(;;) { /* デリミタまで発言転送 */
if (fgets(line1, 82, fr) == NULL) {
break;
}
nowsize -= strlen(line1);
if (*((long *)line1) == 0x0a0d0820) { /* デリミタ(リトルエンディアン用) */
fputs("\r\n", fm);
break;
}
fputs(line1, fm);
}
}
}
fclose(fm);
if ((fw = fopen(workfile, "wb")) == NULL) {
fclose(fr);
return FALSE;
}
setvbuf(fw, vbuf, _IOFBF, VBUFSIZE);
fputs(head1, fw);
fputs(head2, fw);
fputs(mesname, fw);
while (fgets(line1, 82, fr)) {
fputs(line1, fw);
}
fclose(fr);
fclose(fw);
return TRUE;
}